package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.user.DashboardData;
import com.cskaoyan.service.DashboardServiceIpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * \* Description:首页模块
 * \
 */
@RestController
@RequestMapping("admin")
public class DashboardController {
    @Autowired
    DashboardServiceIpl dashboardServiceIpl;

    /**
     * 需要查询四条语句
     * goodsTotal   商品总数量
     * userTotal    用户总数量
     * productTotal 货品总数量
     * orderTotal   订单总数量
     *
     * @return
     */
    @GetMapping("dashboard")
    public BaseRespVo dashboard() {

//查询四条语句,获得总数量
        int goodsTotal = dashboardServiceIpl.goodsTotal();
        int userTotal = dashboardServiceIpl.userTotal();
        int productTotal = dashboardServiceIpl.productTotal();
        int orderTotal = dashboardServiceIpl.orderTotal();

//        将总数量推给Data
        DashboardData data = new DashboardData();
        data.setGoodsTotal(goodsTotal);
        data.setProductTotal(productTotal);
        data.setOrderTotal(orderTotal);
        data.setUserTotal(userTotal);
//返回结果
        return BaseRespVo.ok(data);
    }
}
